package message;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import serveur.MainServer;

public class MessageGetFileInFolder extends Message {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final Logger logger = Logger.getLogger(MainServer.class.getName());
	File[] m_FileList;
	
	public MessageGetFileInFolder ()
	{
		m_iMessageId = Message.GetFileInFolderId;
		m_sMessageName = Message.sGetFileInFolderName;
	}
	
	@Override
	public	boolean execute() {
		boolean bRet = false;
		// Liste tous les fichiers du repertoire courant et stock le resultat
		File repertoire = new File (this.m_sCurrentFolder);
		if (repertoire.isDirectory()) {
			this.m_FileList = repertoire.listFiles();
			m_sResultatExecution ="Execution réussie : liste contenu répertoire";
			m_bResultatExecution = true;
			logger.log(Level.INFO, "Execution de la commande LS");
			bRet = true;
		} else {
			logger.log(Level.WARNING, "LS FAILED - Le repertoire courant n'est pas un dossier");
			m_sResultatExecution ="Execution réussie : la commande a echouee";
		}
		return bRet;
	}

	/**
	 * GETTERS & SETTERS
	 */
	public File[] getM_fileList() {
		return m_FileList;
	}

	public void setM_fileList(File[] FileList) {
		m_FileList = FileList;
	}
}
